
import socket
import threading
import dns.resolver
import sys

IP=None

A=dns.resolver.query('330cc7a7.nat123.fun','A',tcp=True)
for i in A.response.answer:
    for IP1 in i.items:
        print(IP1.address)
        IP=IP1.address

ip=('129.211.74.183',9798)


def say(client):
    while True:
        data=input()
        if data !='exit':
            client.send(data.encode('utf-8'))
        else:
            global tag
            tag=False
            client.send('exit'.encode('utf-8'))
            break

def read(client):
    while True:
        global tag
        if not tag:
            break
        serdata=client.recv(1024)
        if len(serdata)!=0:
            print(serdata.decode('utf-8'))

name=input('输入您的昵称：')
sys.stdout.flush()
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.connect(ip)
print('已连接上服务器！')
client.send(name.encode('utf-8'))
tag=True
client_read=threading.Thread(target=read,args=(client,))
client_say=threading.Thread(target=say,args=(client,))
client_say.start()
client_read.start()
client_read.join()
client_say.join()
client.close()







